package com.fivium.bpd.editor.renderer;

import java.awt.Color;
import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.fivium.bpd.component.QueryDefinition;
import com.fivium.bpd.component.QueryDefinition.QUERY_TYPE;

public class QueryCellRenderer extends AbstractCellRenderer
    implements ListCellRenderer
{
  private static final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);
 
  private static ImageIcon iconApi;
  private static ImageIcon iconQuery;
  private static ImageIcon iconError;
  
  public QueryCellRenderer()
  {
    super();
    
    if (iconApi == null) {
      iconApi = new ImageIcon(getClass().getResource("resource/icon_query_definition_api.png"));
    }
    
    if (iconQuery == null) {
      iconQuery = new ImageIcon(getClass().getResource("resource/icon_query_definition_query.png"));
    }

    if (iconError == null) {
      iconError = new ImageIcon(getClass().getResource("resource/icon_query_definition_unknown.png"));
    }
  }

  @Override
  protected void buildRenderableContent(Object value)
  {
    QueryDefinition query = (QueryDefinition)value;
    
    setText(query.getName());
    
    QUERY_TYPE queryType = query.getType();
    
    if (queryType == null) {
      setIcon(iconError);
    } else {
      switch (query.getType()) {
        case QUERY:
          setIcon(iconQuery);
          break;
        case API:
          setIcon(iconApi);
          break;
      }
    }   
  }

  
}
